package util;

import model.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 得到当前登录的用户
 */
public class SessionUtils {
    /**
     * 获取登录的用户
     *
     * @return
     */
    public static UserInfo getLoginUser(HttpServletRequest req) {
        UserInfo userInfo = null;
        HttpSession session = req.getSession(false);
        if (session != null && session.getAttribute(AppVar.SESSION_USERINFO_KEY) != null) {
            userInfo = (UserInfo) session.getAttribute(AppVar.SESSION_USERINFO_KEY);
        }
        return userInfo;
    }
}
